package com.jiali.backend.controller;

import com.jiali.backend.common.ResponseResult;
import com.jiali.backend.controller.request.StaffAddRequest;
import com.jiali.backend.controller.request.StaffUpdateRequest;
import com.jiali.backend.model.Staff;
import com.jiali.backend.service.StaffService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/staff")
public class StaffController {
    @Resource
    private StaffService staffService;
    //查询所有员工
    @GetMapping("/list")
    public ResponseResult<List<Staff>> getAllStaffs(HttpServletRequest request) {
        return staffService.getAllStaffs(request);
    }
    //查询单个员工-按名称
    @GetMapping("/search")
    public ResponseResult<List<Staff>> searchStaffsByName(
            @RequestParam String name,
            HttpServletRequest request) {
        return staffService.searchStaffsByName(name, request);
    }
    // 根据ID删除员工
    @DeleteMapping("/delete")
    public ResponseResult<Boolean> deleteStaffById(
            @RequestParam Integer id,
            HttpServletRequest request) {
        return staffService.deleteStaffById(id, request);
    }
    // 根据ID查询员工
    @GetMapping("/get")
    public ResponseResult<Staff> getStaffById(
            @RequestParam Integer id,
            HttpServletRequest request) {
        return staffService.getStaffById(id, request);
    }
    @PostMapping("/add")
    public ResponseResult<Staff> addStaff(
            @ModelAttribute StaffAddRequest staffAddRequest, // 使用@ModelAttribute接收表单数据
            HttpServletRequest request) {
        return staffService.addStaff(staffAddRequest, request);
    }
    @PostMapping("/update")
    public ResponseResult<Staff> updateStaff(
            @ModelAttribute StaffUpdateRequest staffUpdateRequest,
            HttpServletRequest request) {
        return staffService.updateStaff(staffUpdateRequest, request);
    }
    @GetMapping("/byPosition")
    public ResponseResult<List<Staff>> getStaffsByPosition(
            @RequestParam Integer position,
            HttpServletRequest request) {
        return staffService.getStaffsByPosition(position, request);
    }
}
